/**
 * Independent time operation tool to facilitate subsequent switch to dayjs
 */
import moment from 'moment';

const DATE_TIME_FORMAT = 'YYYY-MM-DD HH:mm:ss';
const DATE_FORMAT = 'YYYY-MM-DD';
const INTERNATIONAL_TIME_START = 'YYYY-MM-DDT00:00:00';
const INTERNATIONAL_TIME_END = 'YYYY-MM-DDT23:59:59';

export function formatToDateTime(
  date: moment.MomentInput = undefined,
  format = DATE_TIME_FORMAT,
): string {
  return moment(date).format(format);
}

export function formatToDate(date: moment.MomentInput = undefined, format = DATE_FORMAT): string {
  return moment(date).format(format);
}

export const dateUtil = moment;

// 时间范围处理
// 2022-04-21T15:35:24.00Z 时间改为 00:00:00.00 23:59:59.99 然后拼接 getTimeZone() 时区
export function dateRangeProcessing(date) {
  if (date) {
    // date[0] = moment(date[0]).format(INTERNATIONAL_TIME_START) + getTimeZone();
    // date[1] = moment(date[1]).format(INTERNATIONAL_TIME_END) + getTimeZone();
    date[0] = moment(date[0]).format(INTERNATIONAL_TIME_START);
    date[1] = moment(date[1]).format(INTERNATIONAL_TIME_END);
  }
  return date;
}

// 获取到当前时区 例如 +08:00
export function getTimeZone() {
  return moment().format('Z');
}
